#!/usr/bin/php -q
<?PHP
/* Copyright 2005-2018, Lime Technology
 * Copyright 2012-2018, Bergware International.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version 2,
 * as published by the Free Software Foundation.
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 */
?>
<?
echo "<p style='text-align:center'><span class='error label'>错误</span><span class='warn label'>警告</span><span class='system label'>系统</span><span class='array label'>阵列</span></p>\n";

$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
require_once "$docroot/webGui/include/ColorCoding.php";

$ata = exec("ls -n  ".escapeshellarg("/sys/block/{$argv[1]}")."|grep -Po 'ata\d+'");
$dev = $ata ? "${argv[1]}|${ata}[.:]" : $argv[1];
$logs = array_merge(glob("/var/log/syslog.*"),["/var/log/syslog"]);

foreach ($logs as $syslog) {
  exec("grep -P ".escapeshellarg($dev)." ".escapeshellarg($syslog), $lines);
  foreach ($lines as $line) {
    if (strpos($line,'disk_log')!==false) continue;
    $span = "span";
    foreach ($match as $type) foreach ($type['text'] as $text) if (preg_match("/$text/i",$line)) {$span = "span class='{$type['class']}'"; break 2;}
    echo "<$span>".htmlspecialchars($line)."\n</span>";
  }
  unset($lines);
}
?>
